<?php

namespace app\api\controller;

use Qiniu\Auth;

class UploadController extends Base
{

    /**
     * 构造方法
     * @access public
     * @throws \Exception
     */
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * 获取上传token
     */
    public function getToken(){
        $config   = config("filesystem.disks.qiniu");
        $auth = new Auth($config['accessKey'],$config['secretKey']);
        $expires = 3600;
        //自定义返回值
        $returnBody = '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"name":"$(x:name)"}';
        $policy = array(
            'returnBody' => $returnBody
        );
        $upToken = $auth->uploadToken($config['bucket'], null, $expires, $policy, true);
        $this->result($upToken);
    }

}
